<!DOCTYPE html>
<html
		xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
		layout:decorate="page/include/layout"
>
	<head>
		<title>房屋</title>
	</head>
	<body >
		<div class="content" layout:fragment="content">
			<div id="toolbar">
				<button class="btn btn-primary btn-sm" id="add" th:if="${session.s_sysUser.userType==1 or session.s_sysUser.userType==2}">
					<i class="fa fa-plus"></i>添加
				</button>
			</div>
			<table id="table"></table>
			<div id="addHtml" class="invisible">
				<form id="addForm">
					<div class="form-group row">
						<label for="buildingNo" class="col-sm-2 col-form-label">楼号</label>
						<div class="col-sm-10">
							<input type="text" name="buildingNo" class="form-control" id="buildingNo">
						</div>
					</div>
					<div class="form-group row">
						<label for="houseNo" class="col-sm-2 col-form-label">房号</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="houseNo" name="houseNo">
						</div>
					</div>

					<div class="form-group row">
						<label for="houseType" class="col-sm-2 col-form-label">户型</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="houseType" name="houseType">
						</div>
					</div>

					<div class="form-group row">
						<label for="remark" class="col-sm-2 col-form-label">备注</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="remark" name="remark">
						</div>
					</div>
				</form>
			</div>
			<script type="text/javascript">
			var requestPage = pageHouse;
			var requestDetail = getHouse;
			var requestDelete = deleteHouse;
			var requestAdd = addHouse;
			var requestUpdate = updateHouse;
			var moduleName="房屋"

		 	var $table = $('#table')
			//删除
			function remove(id){
				confirm("deleteModal","删除"+moduleName,"确认删除",function(){
					requestDelete(id,function(){
						$("#deleteModal").modal("hide")
						$table.bootstrapTable('refresh')
					})
				})
			}
			var addHTML;
			//修改
			function update(id){
				editModal("updateModal","修改"+moduleName,addHTML,function(){
					var data = getFormData($("#addForm"))
					requestUpdate({id:id,...data},function(res){
						$("#updateModal").modal("hide")
						$table.bootstrapTable('refresh')
					})
				},function(){
					requestDetail(id,function(data){
						initFormValue($("#addForm"),data.data)
					})
				})
			}
			//添加
			function add(){
				editModal("addModal","添加"+moduleName,addHTML,function(){
					var data = getFormData($("#addForm"))
					requestAdd(data,function(res){
						$("#addModal").modal("hide")
						$table.bootstrapTable('refresh')
					})
				})
			}


		 	$(function(){
		 		addHTML = $("#addHtml").html()
		 		$("#addHtml").remove();
				$('#table').bootstrapTable({
				  ajax: function(params){
					var pageRequest = {
						pageNumber: params.data.offset/params.data.limit+1,
						pageSize: params.data.limit
					}
					requestPage(pageRequest,{search:params.data.search},function(data){
						params.success({rows:data.data.content,total:data.data.total})
					})
				  },
				  sidePagination:'server',
				  locale: "zh-CN",
				  pagination: true,
				  toolbar: "#toolbar",
				  search: true,
				  searchHighlight: true,
				  columns: [{
					field: 'id',
					title: '编号'
				  }, {
					field: 'buildingNo',
					title: '楼号'
				  }, {
					field: 'houseNo',
					title: '房号'
				  }, {
					field: 'houseType',
					title: '房屋类型'
				  }, {
					field: 'remark',
					title: '备注'
				  }, {
					field: 'createTime',
					title: '创建日期'
				  }, {
					field: 'updateTime',
					title: '更新日期'
				  },
				  {
					title : '操作',
					field : 'id',
					align : 'center',
					formatter : function(value, row, index) {
						if(userType===1||userType===2){
							var e = '<a class="btn btn-primary btn-sm" href="javascript:void(0);" mce_href="#" title="编辑" onclick="update(\''
								+ row.id
								+ '\')"><i class="fa fa-edit"></i></a> ';
							var d = '<a class="btn btn-warning btn-sm" href="javascript:void(0);" title="删除"  mce_href="#" onclick="remove(\''
								+ row.id
								+ '\')"><i class="fa fa-minus"></i></a> ';
							return e + d;
						}
						return "";
					}
				  }],
				})
				$("#add").on("click",function(){
					add()
				})
			})
		</script>
		</div>
	</body>
</html>